package thin4ca

import java.util.HashSet
import scala.collection.mutable.Set

class EntityDef(val name: String) {
  
  var attributes = Set[String]();
  var relations = Set[Relation]();

   def addRelationTo(e: EntityDef, cardinality: Cardinality.Value) = {
    relations += new Relation(e, cardinality)
    e.addInverseRelationTo(this);
   }
 
  def addRelationTo(e: EntityDef) = {
    addInverseRelationTo(e);
    e.addInverseRelationTo(this);
  } 
   	
  def addInverseRelationTo(e: EntityDef) = {
    relations += new Relation(e, Cardinality.Undefined)
  }

  override def equals(other: Any) = other match {
    case that: EntityDef => name.equals(that.name)
    case _ => false
  }
  
  override def hashCode = name.hashCode

  override def toString = "EntityDef<" + name + ", attrs: " + attributes + ", rel: " + relations + ">";
}
